package me.pinion.controller;

import me.pinion.check.annotation.AllowRole;
import me.pinion.controller.annotation.RouteBind;
import me.pinion.model.Comment;
import me.pinion.service.CommentService;

import java.util.ArrayList;
import java.util.List;

@RouteBind("/comment")
public class CommentController extends Controller{

    CommentService commentService;

    public void index(){

    }

    public void list(){
        String method = getPara("method");
        int id = getParaToInt("id");

        List<Comment> list = new ArrayList<Comment>();
//        if (method.equals("by_post")){
//            list = commentService.listByPost(id);
//        }
        renderJson(list);
    }


    @AllowRole("USER")
    public void create(){
        String clazz = getPara("clazz");
        int id = getParaToInt("id");
        Comment comment = commentService.create(getPara("content"), clazz, id, curUser());

        setAttr("comment", comment);
        render("/book/comment_item.ftl");
    }
}
